<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form :model="where" :inline="true" label-width="77px" @keyup.enter.native="reload" @submit.native.prevent>
        <el-form-item label="用户ID:">
          <el-input clearable v-model="where.member_id" placeholder="请输入用户ID"/>
        </el-form-item>
        <el-form-item label="用户昵称:">
          <el-input clearable v-model="where.nickname" placeholder="请输入用户昵称"/>
        </el-form-item>
        <el-form-item label="商品名称:">
          <el-input clearable v-model="where.name" placeholder="请输入商品名称"/>
        </el-form-item>
        <el-form-item label="订单编号:">
          <el-input clearable v-model="where.order_id" placeholder="请输入订单标号"/>
        </el-form-item>
        <el-form-item label="订单类型:">
          <el-select clearable v-model="where.order_type" placeholder="请选择订单类型" class="ele-fluid">
            <el-option label="全部" value=""/>
            <el-option label="新增设备" value="1"/>
            <el-option label="续费设备" value="2"/>
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态:">
          <el-select clearable v-model="where.order_status" placeholder="请选择订单状态" class="ele-fluid">
            <el-option label="全部" value=""/>
            <el-option label="待支付" value="1"/>
            <el-option label="待发货" value="2"/>
            <el-option label="已完成" value="3"/>
          </el-select>
        </el-form-item>
        <el-form-item label="支付状态:">
          <el-select clearable v-model="where.pay_status" placeholder="请选择支付状态" class="ele-fluid">
            <el-option label="全部" value=""/>
            <el-option label="未支付" value="0"/>
            <el-option label="已支付" value="1"/>
          </el-select>
        </el-form-item>
        <el-form-item label="日期:">
          <el-date-picker style="width: 100%" v-model="where.time_range" type="datetimerange"
                          value-format="yyyy-MM-dd HH:mm:ss" label-format="yyyy-MM-dd HH:mm:ss" range-separator="至"
                          start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item action="">
          <div class="ele-form-actions">
            <el-button type="primary" icon="el-icon-search" class="ele-btn-icon" @click="reload">查询
            </el-button>
            <el-button @click="reset">重置</el-button>
          </div>
        </el-form-item>
      </el-form>
      <!-- 数据表格 -->
      <ele-pro-table ref="table" :where="where" :datasource="url" :columns="columns" :selection.sync="selection"
                     height="calc(100vh - 315px)">
        <template slot="toolbar">
<!--          <el-button-->
<!--            size="small"-->
<!--            type="success"-->
<!--            icon="el-icon-download"-->
<!--            class="ele-btn-icon"-->
<!--            @click="exportExcel"-->
<!--            v-if="permission.includes('sys:box-yun-order:export')">导出-->
<!--          </el-button>-->
        </template>
        <template slot="good_type" slot-scope="{row}">
          <el-tag v-if="row.good_type === 0" type="info" size="small">普通商品</el-tag>
          <el-tag v-if="row.good_type === 1" type="danger" size="small">活动商品</el-tag>
        </template>
        <!-- 订单状态，-1、实付金额校验错误, 0，已取消，1、待支付，2、已支付待发货，3、已完成' -->
        <template slot="order_status" slot-scope="{row}">
          <el-tag v-if="row.order_status === -1" type="danger" size="small">实付金额校验错</el-tag>
          <el-tag v-if="row.order_status === 0" type="info" size="small">已取消</el-tag>
          <el-tag v-if="row.order_status === 1" type="warning" size="small">待支付</el-tag>
          <el-tag v-if="row.order_status === 2" type="" size="small">已支付待发货</el-tag>
          <el-tag v-if="row.order_status === 3" type="success" size="small">已完成</el-tag>
        </template>
        <template slot="order_type" slot-scope="{row}">
          <el-tag v-if="row.order_type === 1" type="success" size="small">新增设备</el-tag>
          <el-tag v-if="row.order_type === 2" type="" size="small">续时设备</el-tag>
        </template>
        <template slot="pay_status" slot-scope="{row}">
          <el-tag v-if="row.pay_status === 0" type="danger" size="small">未支付</el-tag>
          <el-tag v-if="row.pay_status === 1" type="success" size="small">已支付</el-tag>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->
    <!-- <edit :data="current" :visible.sync="showEdit" @done="reload" /> -->
  </div>
</template>

<script>
import {mapGetters} from "vuex";
// import edit from './edit';
import {downloadExcel} from "@/utils/excel-export"

export default {
  name: 'YunOrder',
  // components: { edit },
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/BoxYunOrder/index',
      // 表格列配置
      columns: [
        {
          prop: 'id',
          label: '序号',
          width: 60,
          align: 'center',
          showOverflowTooltip: true,
          fixed: "left"
        },
        {
          prop: 'member_id',
          label: '用户ID',
          width: 120,
          align: 'center',
          showOverflowTooltip: true,
        },
        {
          prop: 'nickname',
          label: '用户昵称',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 120,
        },
        {
          prop: 'num',
          label: '商品数量',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 180,
        },
        {
          prop: 'order_num',
          label: '订单编号',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 280,
        },
        {
          prop: 'order_type',
          label: '订单类型',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 180,
          slot: 'order_type',
        },
        {
          prop: 'order_status',
          label: '订单状态',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 180,
          slot: 'order_status',
        },
        {
          prop: 'create_time',
          label: '下单时间',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 160,
        }
      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
    };
  },
  methods: {
    /* 下载数据Excel */
    exportExcel() {
      downloadExcel(`BoxYunOrder/export`, this.where)
    },

    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    },
    /* 显示编辑 */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
    /* 删除 */
    remove(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/BoxYunGoods/delete', {id: row.id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的商品吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/BoxYunGoods/delete', {id: this.selection.map(d => d.id)}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },
    /* 更改状态 */
    // editStatus(row) {
    //   const loading = this.$loading({ lock: true });
    //   let params = Object.assign({
    //     "id": row.id,
    //     "status": row.status,
    //     "is_time": true
    //   })
    //   this.$http.post('/BoxYunGoods/status', params).then(res => {
    //     loading.close();
    //     if (res.data.code === 0) {
    //       this.$message({ type: 'success', message: res.data.msg });
    //     } else {
    //       row.status = !row.status ? 1 : 2;
    //       this.$message.error(res.data.msg);
    //     }
    //   }).catch(e => {
    //     loading.close();
    //     this.$message.error(e.message);
    //   });
    // }
  }
}
</script>

<style scoped></style>
